#pragma once
#include <stdio.h>
#include <iostream>
#include <string>

int rounds = 0;
string logName = "特种兵的日记.txt";

string Map(string splitToken = "\n")		//输出棋盘
{
	string contentmap;
	for (int i = 0; i <= 11; i++)
	{
		for (int j = 0; j <= 4; j++)
		{
			if ((char(cMap[i][j]) >= 'A') && (char(cMap[i][j]) <= 'Z'))
				contentmap += "13 ";
			else if ((char(cMap[i][j]) == 'j'))
				contentmap += "10 ";
			else if ((char(cMap[i][j]) == 'k'))
				contentmap += "11 ";
			else if ((char(cMap[i][j]) == 'l'))
				contentmap += "12 ";
			else
				contentmap += string(1, char(cMap[i][j]) - 48) + " ";
		}
		contentmap += splitToken;
	}
	return contentmap;
}

string ProbList(string splitToken = "\n")		//输出概率表
{
	string contentprob;
	for (unsigned int i = 0; i < allEnemyChess.size(); i++)
	{
		float sum = (allEnemyChess[i]->sum());
		for (unsigned int j = 0; j < 12; j++)
		{
			contentprob += to_string((allEnemyChess[i]->prob[j]) / sum) + " ";
		}
		contentprob += splitToken;
	}
	return contentprob;
}

string EnemyPos(string splitToken = "\n")		//输出敌方棋子位置
{
	string contentpos;
	for (unsigned int i = 0; i < allEnemyChess.size(); i++)
	{
		contentpos += to_string(allEnemyChess[i]->y) + " " + to_string(allEnemyChess[i]->x) + " ";		//此处按照先行后列进行输出
		contentpos += splitToken;
	}
	return contentpos;
}

string Rounds(string splitToken = "\n")
{
	string contentrounds;
	contentrounds += to_string(rounds) + splitToken;		//输出回合数
	return contentrounds;
}

tuple<int, int> caluChessNum()
{
	int usNum = 0, eneNum = 0;
	for (int i = 0; i <= 11; i++) //计算敌方、我方棋子数
	{
		for (int j = 0; j <= 4; j++)
		{
			if (IsMyChess(i, j))
				usNum += 1;
			if (IsEneChess(i, j))
				eneNum += 1;
		}
	}
	return make_tuple(usNum, eneNum);
}

void outputAllneeds()		//此输出函数使用$号作为分割表格的标志
{
	string content1, content2, content3, content4, content5, content6;
	content1 = Map();
	content1 += "$";
	writeFile(logName, content1);
	content2 = ProbList();
	content2 += "$";
	writeFile(logName, content2);
	content3 = EnemyPos();
	content3 += "$";
	writeFile(logName, content3);

	int usNum = 0, eneNum = 0;
	tie(usNum, eneNum) = caluChessNum();

	content4 += to_string(usNum) + " " + to_string(eneNum) + "\n";		//先输出我方总棋子数  再输出敌方总棋子数
	content4 += "$";
	writeFile(logName, content4);
	content5 = Rounds();
	content5 += "$";
	writeFile(logName, content5);
	float ff1, ff2, ff3, ff4, ff5, ff6, ff7;
	tie(ff1, ff2, ff3, ff4, ff5, ff6, ff7, ignore) = assess::valueEstimation(cMap);
	content6 += to_string(ff1) + " " + to_string(ff2) + " " + to_string(ff3) + " " + to_string(ff4) + " " + to_string(ff5) + " " + to_string(ff6) + " " + to_string(ff7) + "\n";		//输出局面评估函数值
	content6 += "@";		//回合结束使用@进行分割
	writeFile(logName, content6);
}
